package com.ly.utils;

import lombok.Data;

@Data
public class Result {
    //这个类用于统一结果的包装

    private static final String SUCCESS_CODE = "200";
    public static final String SUCCESS_MSG = "处理成功";
    private static final String ERROR_CODE = "401";
    public static final String ERROR_MSG = "系统异常";
    public static final String WARN_CODE = "300";
    public static final String WARN_MSG = "操作错误";

    private String code;
    private Object data;
    private String msg;
    public static Result success(){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setMsg(SUCCESS_MSG);
        return result;
    }

    public static Result success(Object data){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setMsg(SUCCESS_MSG);
        result.setData(data);
        return result;
    }


    public static Result success(Object data,String msg){
        Result result = new Result();
        result.setCode(SUCCESS_CODE);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result warn( String msg){
        Result result = new Result();
        result.setCode(WARN_CODE);
        result.setMsg(msg);
        return result;
    }

    public static Result warn( String code,String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static Result warn( ){
        Result result = new Result();
        result.setCode(WARN_CODE);
        result.setMsg(WARN_MSG);
        return result;
    }

    public static Result error( ){
        Result result = new Result();
        result.setCode(ERROR_CODE);
        result.setMsg(ERROR_MSG);
        return result;
    }
    public static Result error( String msg){
        Result result = new Result();
        result.setCode(ERROR_CODE);
        result.setMsg(msg);
        return result;
    }
    public static Result error( String code,String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
